﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using LCrs.DBUtility;//Please add references
namespace LCrs.DAL
{
	/// <summary>
	/// 数据访问类:PersonInfo
	/// </summary>
	public partial class PersonInfo
	{
		public PersonInfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("pid", "PersonInfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int pid)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from PersonInfo");
			strSql.Append(" where pid=@pid");
			SqlParameter[] parameters = {
					new SqlParameter("@pid", SqlDbType.Int,4)
			};
			parameters[0].Value = pid;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(LCrs.Model.PersonInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into PersonInfo(");
			strSql.Append("pname,ID,birthday,zname,porigin,birthadd,sex,nation,marital,health,political,workday,degree,education,eduday,eduschool,edumajor,edumajortype,workname,workjgtype,workjjtype,worktrade,workjobtype,workarea,hjadd,hjarea,address,zip,phnoe,email,filename,fnamecode,fnamebh,fjgtype,fjjtype,ftrade,farea,fbh,findex,fstatus,ftype,fmanagername,inday,inreason,oldname,oldarea,outday,outreason,newname,newarea,drelation,hrelation,sbrelation,status,remark,inputtime)");
			strSql.Append(" values (");
			strSql.Append("@pname,@ID,@birthday,@zname,@porigin,@birthadd,@sex,@nation,@marital,@health,@political,@workday,@degree,@education,@eduday,@eduschool,@edumajor,@edumajortype,@workname,@workjgtype,@workjjtype,@worktrade,@workjobtype,@workarea,@hjadd,@hjarea,@address,@zip,@phnoe,@email,@filename,@fnamecode,@fnamebh,@fjgtype,@fjjtype,@ftrade,@farea,@fbh,@findex,@fstatus,@ftype,@fmanagername,@inday,@inreason,@oldname,@oldarea,@outday,@outreason,@newname,@newarea,@drelation,@hrelation,@sbrelation,@status,@remark,@inputtime)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@pname", SqlDbType.NVarChar,20),
					new SqlParameter("@ID", SqlDbType.VarChar,18),
					new SqlParameter("@birthday", SqlDbType.SmallDateTime),
					new SqlParameter("@zname", SqlDbType.NVarChar,20),
					new SqlParameter("@porigin", SqlDbType.NVarChar,100),
					new SqlParameter("@birthadd", SqlDbType.NVarChar,100),
					new SqlParameter("@sex", SqlDbType.NVarChar,10),
					new SqlParameter("@nation", SqlDbType.NVarChar,20),
					new SqlParameter("@marital", SqlDbType.VarChar,10),
					new SqlParameter("@health", SqlDbType.VarChar,20),
					new SqlParameter("@political", SqlDbType.NVarChar,10),
					new SqlParameter("@workday", SqlDbType.VarChar,20),
					new SqlParameter("@degree", SqlDbType.NVarChar,20),
					new SqlParameter("@education", SqlDbType.NVarChar,20),
					new SqlParameter("@eduday", SqlDbType.SmallDateTime),
					new SqlParameter("@eduschool", SqlDbType.NVarChar,20),
					new SqlParameter("@edumajor", SqlDbType.NVarChar,20),
					new SqlParameter("@edumajortype", SqlDbType.NVarChar,20),
					new SqlParameter("@workname", SqlDbType.NVarChar,50),
					new SqlParameter("@workjgtype", SqlDbType.NVarChar,10),
					new SqlParameter("@workjjtype", SqlDbType.NVarChar,10),
					new SqlParameter("@worktrade", SqlDbType.NVarChar,20),
					new SqlParameter("@workjobtype", SqlDbType.NVarChar,10),
					new SqlParameter("@workarea", SqlDbType.NVarChar,10),
					new SqlParameter("@hjadd", SqlDbType.NVarChar,50),
					new SqlParameter("@hjarea", SqlDbType.NVarChar,10),
					new SqlParameter("@address", SqlDbType.NVarChar,100),
					new SqlParameter("@zip", SqlDbType.VarChar,15),
					new SqlParameter("@phnoe", SqlDbType.VarChar,15),
					new SqlParameter("@email", SqlDbType.NVarChar,30),
					new SqlParameter("@filename", SqlDbType.NVarChar,20),
					new SqlParameter("@fnamecode", SqlDbType.NVarChar,20),
					new SqlParameter("@fnamebh", SqlDbType.NVarChar,20),
					new SqlParameter("@fjgtype", SqlDbType.NVarChar,10),
					new SqlParameter("@fjjtype", SqlDbType.NVarChar,10),
					new SqlParameter("@ftrade", SqlDbType.NVarChar,20),
					new SqlParameter("@farea", SqlDbType.NVarChar,10),
					new SqlParameter("@fbh", SqlDbType.NVarChar,20),
					new SqlParameter("@findex", SqlDbType.NVarChar,20),
					new SqlParameter("@fstatus", SqlDbType.NVarChar,10),
					new SqlParameter("@ftype", SqlDbType.NVarChar,10),
					new SqlParameter("@fmanagername", SqlDbType.NVarChar,20),
					new SqlParameter("@inday", SqlDbType.SmallDateTime),
					new SqlParameter("@inreason", SqlDbType.NVarChar,100),
					new SqlParameter("@oldname", SqlDbType.NVarChar,20),
					new SqlParameter("@oldarea", SqlDbType.NVarChar,10),
					new SqlParameter("@outday", SqlDbType.SmallDateTime),
					new SqlParameter("@outreason", SqlDbType.NVarChar,100),
					new SqlParameter("@newname", SqlDbType.NVarChar,20),
					new SqlParameter("@newarea", SqlDbType.NVarChar,10),
					new SqlParameter("@drelation", SqlDbType.Int,4),
					new SqlParameter("@hrelation", SqlDbType.Int,4),
					new SqlParameter("@sbrelation", SqlDbType.Int,4),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@remark", SqlDbType.NVarChar,50),
					new SqlParameter("@inputtime", SqlDbType.SmallDateTime)};
			parameters[0].Value = model.pname;
			parameters[1].Value = model.ID;
			parameters[2].Value = model.birthday;
			parameters[3].Value = model.zname;
			parameters[4].Value = model.porigin;
			parameters[5].Value = model.birthadd;
			parameters[6].Value = model.sex;
			parameters[7].Value = model.nation;
			parameters[8].Value = model.marital;
			parameters[9].Value = model.health;
			parameters[10].Value = model.political;
			parameters[11].Value = model.workday;
			parameters[12].Value = model.degree;
			parameters[13].Value = model.education;
			parameters[14].Value = model.eduday;
			parameters[15].Value = model.eduschool;
			parameters[16].Value = model.edumajor;
			parameters[17].Value = model.edumajortype;
			parameters[18].Value = model.workname;
			parameters[19].Value = model.workjgtype;
			parameters[20].Value = model.workjjtype;
			parameters[21].Value = model.worktrade;
			parameters[22].Value = model.workjobtype;
			parameters[23].Value = model.workarea;
			parameters[24].Value = model.hjadd;
			parameters[25].Value = model.hjarea;
			parameters[26].Value = model.address;
			parameters[27].Value = model.zip;
			parameters[28].Value = model.phnoe;
			parameters[29].Value = model.email;
			parameters[30].Value = model.filename;
			parameters[31].Value = model.fnamecode;
			parameters[32].Value = model.fnamebh;
			parameters[33].Value = model.fjgtype;
			parameters[34].Value = model.fjjtype;
			parameters[35].Value = model.ftrade;
			parameters[36].Value = model.farea;
			parameters[37].Value = model.fbh;
			parameters[38].Value = model.findex;
			parameters[39].Value = model.fstatus;
			parameters[40].Value = model.ftype;
			parameters[41].Value = model.fmanagername;
			parameters[42].Value = model.inday;
			parameters[43].Value = model.inreason;
			parameters[44].Value = model.oldname;
			parameters[45].Value = model.oldarea;
			parameters[46].Value = model.outday;
			parameters[47].Value = model.outreason;
			parameters[48].Value = model.newname;
			parameters[49].Value = model.newarea;
			parameters[50].Value = model.drelation;
			parameters[51].Value = model.hrelation;
			parameters[52].Value = model.sbrelation;
			parameters[53].Value = model.status;
			parameters[54].Value = model.remark;
			parameters[55].Value = model.inputtime;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(LCrs.Model.PersonInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update PersonInfo set ");
			strSql.Append("pname=@pname,");
			strSql.Append("ID=@ID,");
			strSql.Append("birthday=@birthday,");
			strSql.Append("zname=@zname,");
			strSql.Append("porigin=@porigin,");
			strSql.Append("birthadd=@birthadd,");
			strSql.Append("sex=@sex,");
			strSql.Append("nation=@nation,");
			strSql.Append("marital=@marital,");
			strSql.Append("health=@health,");
			strSql.Append("political=@political,");
			strSql.Append("workday=@workday,");
			strSql.Append("degree=@degree,");
			strSql.Append("education=@education,");
			strSql.Append("eduday=@eduday,");
			strSql.Append("eduschool=@eduschool,");
			strSql.Append("edumajor=@edumajor,");
			strSql.Append("edumajortype=@edumajortype,");
			strSql.Append("workname=@workname,");
			strSql.Append("workjgtype=@workjgtype,");
			strSql.Append("workjjtype=@workjjtype,");
			strSql.Append("worktrade=@worktrade,");
			strSql.Append("workjobtype=@workjobtype,");
			strSql.Append("workarea=@workarea,");
			strSql.Append("hjadd=@hjadd,");
			strSql.Append("hjarea=@hjarea,");
			strSql.Append("address=@address,");
			strSql.Append("zip=@zip,");
			strSql.Append("phnoe=@phnoe,");
			strSql.Append("email=@email,");
			strSql.Append("filename=@filename,");
			strSql.Append("fnamecode=@fnamecode,");
			strSql.Append("fnamebh=@fnamebh,");
			strSql.Append("fjgtype=@fjgtype,");
			strSql.Append("fjjtype=@fjjtype,");
			strSql.Append("ftrade=@ftrade,");
			strSql.Append("farea=@farea,");
			strSql.Append("fbh=@fbh,");
			strSql.Append("findex=@findex,");
			strSql.Append("fstatus=@fstatus,");
			strSql.Append("ftype=@ftype,");
			strSql.Append("fmanagername=@fmanagername,");
			strSql.Append("inday=@inday,");
			strSql.Append("inreason=@inreason,");
			strSql.Append("oldname=@oldname,");
			strSql.Append("oldarea=@oldarea,");
			strSql.Append("outday=@outday,");
			strSql.Append("outreason=@outreason,");
			strSql.Append("newname=@newname,");
			strSql.Append("newarea=@newarea,");
            strSql.Append("status=@status,");
            strSql.Append("remark=@remark");
			
			strSql.Append(" where pid=@pid");
			SqlParameter[] parameters = {
					new SqlParameter("@pname", SqlDbType.NVarChar,20),
					new SqlParameter("@ID", SqlDbType.VarChar,18),
					new SqlParameter("@birthday", SqlDbType.SmallDateTime),
					new SqlParameter("@zname", SqlDbType.NVarChar,20),
					new SqlParameter("@porigin", SqlDbType.NVarChar,100),
					new SqlParameter("@birthadd", SqlDbType.NVarChar,100),
					new SqlParameter("@sex", SqlDbType.NVarChar,10),
					new SqlParameter("@nation", SqlDbType.NVarChar,20),
					new SqlParameter("@marital", SqlDbType.VarChar,10),
					new SqlParameter("@health", SqlDbType.VarChar,20),
					new SqlParameter("@political", SqlDbType.NVarChar,10),
					new SqlParameter("@workday", SqlDbType.VarChar,20),
					new SqlParameter("@degree", SqlDbType.NVarChar,20),
					new SqlParameter("@education", SqlDbType.NVarChar,20),
					new SqlParameter("@eduday", SqlDbType.SmallDateTime),
					new SqlParameter("@eduschool", SqlDbType.NVarChar,20),
					new SqlParameter("@edumajor", SqlDbType.NVarChar,20),
					new SqlParameter("@edumajortype", SqlDbType.NVarChar,20),
					new SqlParameter("@workname", SqlDbType.NVarChar,50),
					new SqlParameter("@workjgtype", SqlDbType.NVarChar,10),
					new SqlParameter("@workjjtype", SqlDbType.NVarChar,10),
					new SqlParameter("@worktrade", SqlDbType.NVarChar,20),
					new SqlParameter("@workjobtype", SqlDbType.NVarChar,10),
					new SqlParameter("@workarea", SqlDbType.NVarChar,10),
					new SqlParameter("@hjadd", SqlDbType.NVarChar,50),
					new SqlParameter("@hjarea", SqlDbType.NVarChar,10),
					new SqlParameter("@address", SqlDbType.NVarChar,100),
					new SqlParameter("@zip", SqlDbType.VarChar,15),
					new SqlParameter("@phnoe", SqlDbType.VarChar,15),
					new SqlParameter("@email", SqlDbType.NVarChar,30),
					new SqlParameter("@filename", SqlDbType.NVarChar,20),
					new SqlParameter("@fnamecode", SqlDbType.NVarChar,20),
					new SqlParameter("@fnamebh", SqlDbType.NVarChar,20),
					new SqlParameter("@fjgtype", SqlDbType.NVarChar,10),
					new SqlParameter("@fjjtype", SqlDbType.NVarChar,10),
					new SqlParameter("@ftrade", SqlDbType.NVarChar,20),
					new SqlParameter("@farea", SqlDbType.NVarChar,10),
					new SqlParameter("@fbh", SqlDbType.NVarChar,20),
					new SqlParameter("@findex", SqlDbType.NVarChar,20),
					new SqlParameter("@fstatus", SqlDbType.NVarChar,10),
					new SqlParameter("@ftype", SqlDbType.NVarChar,10),
					new SqlParameter("@fmanagername", SqlDbType.NVarChar,20),
					new SqlParameter("@inday", SqlDbType.SmallDateTime),
					new SqlParameter("@inreason", SqlDbType.NVarChar,100),
					new SqlParameter("@oldname", SqlDbType.NVarChar,20),
					new SqlParameter("@oldarea", SqlDbType.NVarChar,10),
					new SqlParameter("@outday", SqlDbType.SmallDateTime),
					new SqlParameter("@outreason", SqlDbType.NVarChar,100),
					new SqlParameter("@newname", SqlDbType.NVarChar,20),
					new SqlParameter("@newarea", SqlDbType.NVarChar,10),
                    new SqlParameter("@status", SqlDbType.Int,4),
                    new SqlParameter("@remark", SqlDbType.NVarChar,50),					
					new SqlParameter("@pid", SqlDbType.Int,4)};
			parameters[0].Value = model.pname;
			parameters[1].Value = model.ID;
			parameters[2].Value = model.birthday;
			parameters[3].Value = model.zname;
			parameters[4].Value = model.porigin;
			parameters[5].Value = model.birthadd;
			parameters[6].Value = model.sex;
			parameters[7].Value = model.nation;
			parameters[8].Value = model.marital;
			parameters[9].Value = model.health;
			parameters[10].Value = model.political;
			parameters[11].Value = model.workday;
			parameters[12].Value = model.degree;
			parameters[13].Value = model.education;
			parameters[14].Value = model.eduday;
			parameters[15].Value = model.eduschool;
			parameters[16].Value = model.edumajor;
			parameters[17].Value = model.edumajortype;
			parameters[18].Value = model.workname;
			parameters[19].Value = model.workjgtype;
			parameters[20].Value = model.workjjtype;
			parameters[21].Value = model.worktrade;
			parameters[22].Value = model.workjobtype;
			parameters[23].Value = model.workarea;
			parameters[24].Value = model.hjadd;
			parameters[25].Value = model.hjarea;
			parameters[26].Value = model.address;
			parameters[27].Value = model.zip;
			parameters[28].Value = model.phnoe;
			parameters[29].Value = model.email;
			parameters[30].Value = model.filename;
			parameters[31].Value = model.fnamecode;
			parameters[32].Value = model.fnamebh;
			parameters[33].Value = model.fjgtype;
			parameters[34].Value = model.fjjtype;
			parameters[35].Value = model.ftrade;
			parameters[36].Value = model.farea;
			parameters[37].Value = model.fbh;
			parameters[38].Value = model.findex;
			parameters[39].Value = model.fstatus;
			parameters[40].Value = model.ftype;
			parameters[41].Value = model.fmanagername;
			parameters[42].Value = model.inday;
			parameters[43].Value = model.inreason;
			parameters[44].Value = model.oldname;
			parameters[45].Value = model.oldarea;
			parameters[46].Value = model.outday;
			parameters[47].Value = model.outreason;
			parameters[48].Value = model.newname;
			parameters[49].Value = model.newarea;
            parameters[50].Value = model.status;
			parameters[51].Value = model.remark;
			parameters[52].Value = model.pid;			

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int pid)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from PersonInfo ");
			strSql.Append(" where pid=@pid");
			SqlParameter[] parameters = {
					new SqlParameter("@pid", SqlDbType.Int,4)
			};
			parameters[0].Value = pid;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string pidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from PersonInfo ");
			strSql.Append(" where pid in ("+pidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public LCrs.Model.PersonInfo GetModel(int pid)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 pid,pname,ID,birthday,zname,porigin,birthadd,sex,nation,marital,health,political,workday,degree,education,eduday,eduschool,edumajor,edumajortype,workname,workjgtype,workjjtype,worktrade,workjobtype,workarea,hjadd,hjarea,address,zip,phnoe,email,filename,fnamecode,fnamebh,fjgtype,fjjtype,ftrade,farea,fbh,findex,fstatus,ftype,fmanagername,inday,inreason,oldname,oldarea,outday,outreason,newname,newarea,drelation,hrelation,sbrelation,status,remark,inputtime from PersonInfo ");
			strSql.Append(" where pid=@pid");
			SqlParameter[] parameters = {
					new SqlParameter("@pid", SqlDbType.Int,4)
			};
			parameters[0].Value = pid;

			LCrs.Model.PersonInfo model=new LCrs.Model.PersonInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public LCrs.Model.PersonInfo DataRowToModel(DataRow row)
		{
			LCrs.Model.PersonInfo model=new LCrs.Model.PersonInfo();
			if (row != null)
			{
				if(row["pid"]!=null && row["pid"].ToString()!="")
				{
					model.pid=int.Parse(row["pid"].ToString());
				}
				if(row["pname"]!=null)
				{
					model.pname=row["pname"].ToString();
				}
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["birthday"]!=null && row["birthday"].ToString()!="")
				{
					model.birthday=DateTime.Parse(row["birthday"].ToString());
				}
				if(row["zname"]!=null)
				{
					model.zname=row["zname"].ToString();
				}
				if(row["porigin"]!=null)
				{
					model.porigin=row["porigin"].ToString();
				}
				if(row["birthadd"]!=null)
				{
					model.birthadd=row["birthadd"].ToString();
				}
				if(row["sex"]!=null)
				{
					model.sex=row["sex"].ToString();
				}
				if(row["nation"]!=null)
				{
					model.nation=row["nation"].ToString();
				}
				if(row["marital"]!=null)
				{
					model.marital=row["marital"].ToString();
				}
				if(row["health"]!=null)
				{
					model.health=row["health"].ToString();
				}
				if(row["political"]!=null)
				{
					model.political=row["political"].ToString();
				}
				if(row["workday"]!=null)
				{
					model.workday=row["workday"].ToString();
				}
				if(row["degree"]!=null)
				{
					model.degree=row["degree"].ToString();
				}
				if(row["education"]!=null)
				{
					model.education=row["education"].ToString();
				}
				if(row["eduday"]!=null && row["eduday"].ToString()!="")
				{
					model.eduday=DateTime.Parse(row["eduday"].ToString());
				}
				if(row["eduschool"]!=null)
				{
					model.eduschool=row["eduschool"].ToString();
				}
				if(row["edumajor"]!=null)
				{
					model.edumajor=row["edumajor"].ToString();
				}
				if(row["edumajortype"]!=null)
				{
					model.edumajortype=row["edumajortype"].ToString();
				}
				if(row["workname"]!=null)
				{
					model.workname=row["workname"].ToString();
				}
				if(row["workjgtype"]!=null)
				{
					model.workjgtype=row["workjgtype"].ToString();
				}
				if(row["workjjtype"]!=null)
				{
					model.workjjtype=row["workjjtype"].ToString();
				}
				if(row["worktrade"]!=null)
				{
					model.worktrade=row["worktrade"].ToString();
				}
				if(row["workjobtype"]!=null)
				{
					model.workjobtype=row["workjobtype"].ToString();
				}
				if(row["workarea"]!=null)
				{
					model.workarea=row["workarea"].ToString();
				}
				if(row["hjadd"]!=null)
				{
					model.hjadd=row["hjadd"].ToString();
				}
				if(row["hjarea"]!=null)
				{
					model.hjarea=row["hjarea"].ToString();
				}
				if(row["address"]!=null)
				{
					model.address=row["address"].ToString();
				}
				if(row["zip"]!=null)
				{
					model.zip=row["zip"].ToString();
				}
				if(row["phnoe"]!=null)
				{
					model.phnoe=row["phnoe"].ToString();
				}
				if(row["email"]!=null)
				{
					model.email=row["email"].ToString();
				}
				if(row["filename"]!=null)
				{
					model.filename=row["filename"].ToString();
				}
				if(row["fnamecode"]!=null)
				{
					model.fnamecode=row["fnamecode"].ToString();
				}
				if(row["fnamebh"]!=null)
				{
					model.fnamebh=row["fnamebh"].ToString();
				}
				if(row["fjgtype"]!=null)
				{
					model.fjgtype=row["fjgtype"].ToString();
				}
				if(row["fjjtype"]!=null)
				{
					model.fjjtype=row["fjjtype"].ToString();
				}
				if(row["ftrade"]!=null)
				{
					model.ftrade=row["ftrade"].ToString();
				}
				if(row["farea"]!=null)
				{
					model.farea=row["farea"].ToString();
				}
				if(row["fbh"]!=null)
				{
					model.fbh=row["fbh"].ToString();
				}
				if(row["findex"]!=null)
				{
					model.findex=row["findex"].ToString();
				}
				if(row["fstatus"]!=null)
				{
					model.fstatus=row["fstatus"].ToString();
				}
				if(row["ftype"]!=null)
				{
					model.ftype=row["ftype"].ToString();
				}
				if(row["fmanagername"]!=null)
				{
					model.fmanagername=row["fmanagername"].ToString();
				}
				if(row["inday"]!=null && row["inday"].ToString()!="")
				{
					model.inday=DateTime.Parse(row["inday"].ToString());
				}
				if(row["inreason"]!=null)
				{
					model.inreason=row["inreason"].ToString();
				}
				if(row["oldname"]!=null)
				{
					model.oldname=row["oldname"].ToString();
				}
				if(row["oldarea"]!=null)
				{
					model.oldarea=row["oldarea"].ToString();
				}
				if(row["outday"]!=null && row["outday"].ToString()!="")
				{
					model.outday=DateTime.Parse(row["outday"].ToString());
				}
				if(row["outreason"]!=null)
				{
					model.outreason=row["outreason"].ToString();
				}
				if(row["newname"]!=null)
				{
					model.newname=row["newname"].ToString();
				}
				if(row["newarea"]!=null)
				{
					model.newarea=row["newarea"].ToString();
				}
				if(row["drelation"]!=null && row["drelation"].ToString()!="")
				{
					model.drelation=int.Parse(row["drelation"].ToString());
				}
				if(row["hrelation"]!=null && row["hrelation"].ToString()!="")
				{
					model.hrelation=int.Parse(row["hrelation"].ToString());
				}
				if(row["sbrelation"]!=null && row["sbrelation"].ToString()!="")
				{
					model.sbrelation=int.Parse(row["sbrelation"].ToString());
				}
				if(row["status"]!=null && row["status"].ToString()!="")
				{
					model.status=int.Parse(row["status"].ToString());
				}
				if(row["remark"]!=null)
				{
					model.remark=row["remark"].ToString();
				}
				if(row["inputtime"]!=null && row["inputtime"].ToString()!="")
				{
					model.inputtime=DateTime.Parse(row["inputtime"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select pid,pname,ID,birthday,zname,porigin,birthadd,sex,nation,marital,health,political,workday,degree,education,eduday,eduschool,edumajor,edumajortype,workname,workjgtype,workjjtype,worktrade,workjobtype,workarea,hjadd,hjarea,address,zip,phnoe,email,filename,fnamecode,fnamebh,fjgtype,fjjtype,ftrade,farea,fbh,findex,fstatus,ftype,fmanagername,inday,inreason,oldname,oldarea,outday,outreason,newname,newarea,drelation,hrelation,sbrelation,status,remark,inputtime ");
			strSql.Append(" FROM PersonInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(filedOrder);
			strSql.Append(" FROM VPersonadd ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}			
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM PersonInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.pid desc");
			}
			strSql.Append(")AS Row, T.*  from VPersonInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}
        public DataSet GetListByPage(string fileds,string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.pid desc");
            }
            strSql.Append(")AS Row, T.*  from VPersonInfo T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "PersonInfo";
			parameters[1].Value = "pid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

        #endregion  BasicMethod
        #region  ExtensionMethod
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateDHS(LCrs.Model.PersonInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PersonInfo set ");
            strSql.Append("drelation=@drelation,");
            strSql.Append("hrelation=@hrelation,");
            strSql.Append("sbrelation=@sbrelation");

            strSql.Append(" where pid=@pid");
            SqlParameter[] parameters = {
                    new SqlParameter("@drelation", SqlDbType.Int,4),
                    new SqlParameter("@hrelation", SqlDbType.Int,4),
                    new SqlParameter("@sbrelation", SqlDbType.Int,4),
                    new SqlParameter("@pid", SqlDbType.Int,4)};
           
            parameters[0].Value = model.drelation;
            parameters[1].Value = model.hrelation;
            parameters[2].Value = model.sbrelation;
            parameters[3].Value = model.pid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion  ExtensionMethod
    }
}

